package com.rajaev.dtu.tractor.infrastructure.config.mongo.codec;

import com.rajaev.dtu.tractor.domain.vo.BmsHourlyStaticResult;
import org.bson.BsonReader;
import org.bson.BsonWriter;
import org.bson.codecs.Codec;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.EncoderContext;

/**
 * @Created with IDEA
 * @author: tianjie
 * @Date:2019/6/17
 * @Time:16:25
 */
public class BmsHourlyResultCodec implements Codec<BmsHourlyStaticResult> {
    @Override
    public BmsHourlyStaticResult decode(BsonReader reader, DecoderContext decoderContext) {
        BmsHourlyStaticResult.BmsHourlyStaticResultBuilder builider = BmsHourlyStaticResult.builder();
        reader.readStartDocument();
        reader.readObjectId("_id");

        builider.disChargeTime(reader.readInt64("disChargeTime"))
                .chargeElectricity(reader.readDouble("chargeElectricity"))
                .dischargeElectricity(reader.readDouble("dischargeElectricity"))
                .customerId(reader.readString("customerId"))
                .online(reader.readBoolean("online"))
                .onlineTime(reader.readInt64("onlineTime"))
                .vin(reader.readString("vin"))
                .dataDateHour(reader.readInt32("dataDateHour"));
        reader.readEndDocument();

        return builider.build();
    }

    @Override
    public void encode(BsonWriter writer, BmsHourlyStaticResult value, EncoderContext encoderContext) {

    }

    @Override
    public Class<BmsHourlyStaticResult> getEncoderClass() {
        return BmsHourlyStaticResult.class;
    }
}
